// 对fs的异步方法进行Promise封装 -> 太麻烦
/* const path = require('path');
const fs = require('fs');

function readFilePro(url, encode) {
    return new Promise(function (resolve, reject) {
        fs.readFile(url, encode, function (err, txt) {
            if (!err) {
                resolve(txt)
            } else {
                reject(err)
            }
        })
    })
}

readFilePro(path.join(__dirname, "../data/2.txt"), "utf-8").then(res => {
    console.log("读取成功", res);
}).catch(err => {
    console.log("读取失败", err);
}) */

const path = require('path');

// 旧版本
// const fs = require('fs');
// const fsp = fs.promises;

// 新版 (16以及以上)
const fsp = require('fs/promises');

// console.log(fs);
// console.log(fsp);


fsp.readFile(path.join(__dirname, "../data/2.txt"), "utf-8").then(res => {
    console.log("读取成功", res);
}).catch(err => {
    console.log("读取失败", err);
})
